/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package reamodel.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

import reamodel.EconomicAgent;
import reamodel.EconomicEvent;
import reamodel.ReamodelPackage;
import reamodel.ReceiveParticipation;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Receive Participation</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link reamodel.impl.ReceiveParticipationImpl#getEvent <em>Event</em>}</li>
 *   <li>{@link reamodel.impl.ReceiveParticipationImpl#getAgent <em>Agent</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ReceiveParticipationImpl extends ParticipationImpl implements ReceiveParticipation {
	/**
	 * The cached value of the '{@link #getEvent() <em>Event</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEvent()
	 * @generated
	 * @ordered
	 */
	protected EconomicEvent event;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ReceiveParticipationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ReamodelPackage.Literals.RECEIVE_PARTICIPATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EconomicEvent getEvent() {
		if (event != null && event.eIsProxy()) {
			InternalEObject oldEvent = (InternalEObject)event;
			event = (EconomicEvent)eResolveProxy(oldEvent);
			if (event != oldEvent) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, ReamodelPackage.RECEIVE_PARTICIPATION__EVENT, oldEvent, event));
			}
		}
		return event;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EconomicEvent basicGetEvent() {
		return event;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetEvent(EconomicEvent newEvent, NotificationChain msgs) {
		EconomicEvent oldEvent = event;
		event = newEvent;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ReamodelPackage.RECEIVE_PARTICIPATION__EVENT, oldEvent, newEvent);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEvent(EconomicEvent newEvent) {
		if (newEvent != event) {
			NotificationChain msgs = null;
			if (event != null)
				msgs = ((InternalEObject)event).eInverseRemove(this, ReamodelPackage.ECONOMIC_EVENT__RECEIVER, EconomicEvent.class, msgs);
			if (newEvent != null)
				msgs = ((InternalEObject)newEvent).eInverseAdd(this, ReamodelPackage.ECONOMIC_EVENT__RECEIVER, EconomicEvent.class, msgs);
			msgs = basicSetEvent(newEvent, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ReamodelPackage.RECEIVE_PARTICIPATION__EVENT, newEvent, newEvent));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EconomicAgent getAgent() {
		if (eContainerFeatureID != ReamodelPackage.RECEIVE_PARTICIPATION__AGENT) return null;
		return (EconomicAgent)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetAgent(EconomicAgent newAgent, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newAgent, ReamodelPackage.RECEIVE_PARTICIPATION__AGENT, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAgent(EconomicAgent newAgent) {
		if (newAgent != eInternalContainer() || (eContainerFeatureID != ReamodelPackage.RECEIVE_PARTICIPATION__AGENT && newAgent != null)) {
			if (EcoreUtil.isAncestor(this, newAgent))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newAgent != null)
				msgs = ((InternalEObject)newAgent).eInverseAdd(this, ReamodelPackage.ECONOMIC_AGENT__RECEIVES, EconomicAgent.class, msgs);
			msgs = basicSetAgent(newAgent, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ReamodelPackage.RECEIVE_PARTICIPATION__AGENT, newAgent, newAgent));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.RECEIVE_PARTICIPATION__EVENT:
				if (event != null)
					msgs = ((InternalEObject)event).eInverseRemove(this, ReamodelPackage.ECONOMIC_EVENT__RECEIVER, EconomicEvent.class, msgs);
				return basicSetEvent((EconomicEvent)otherEnd, msgs);
			case ReamodelPackage.RECEIVE_PARTICIPATION__AGENT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetAgent((EconomicAgent)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.RECEIVE_PARTICIPATION__EVENT:
				return basicSetEvent(null, msgs);
			case ReamodelPackage.RECEIVE_PARTICIPATION__AGENT:
				return basicSetAgent(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID) {
			case ReamodelPackage.RECEIVE_PARTICIPATION__AGENT:
				return eInternalContainer().eInverseRemove(this, ReamodelPackage.ECONOMIC_AGENT__RECEIVES, EconomicAgent.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ReamodelPackage.RECEIVE_PARTICIPATION__EVENT:
				if (resolve) return getEvent();
				return basicGetEvent();
			case ReamodelPackage.RECEIVE_PARTICIPATION__AGENT:
				return getAgent();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ReamodelPackage.RECEIVE_PARTICIPATION__EVENT:
				setEvent((EconomicEvent)newValue);
				return;
			case ReamodelPackage.RECEIVE_PARTICIPATION__AGENT:
				setAgent((EconomicAgent)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ReamodelPackage.RECEIVE_PARTICIPATION__EVENT:
				setEvent((EconomicEvent)null);
				return;
			case ReamodelPackage.RECEIVE_PARTICIPATION__AGENT:
				setAgent((EconomicAgent)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ReamodelPackage.RECEIVE_PARTICIPATION__EVENT:
				return event != null;
			case ReamodelPackage.RECEIVE_PARTICIPATION__AGENT:
				return getAgent() != null;
		}
		return super.eIsSet(featureID);
	}

} //ReceiveParticipationImpl
